#pragma once
#include <map>
#include <deque>
#include <mutex>
#include <optional>

namespace WD {
    
struct SubtitleInfo {
    int seq = -1;
    int exposure_time = 0;
    int scan_time = 0;
    uint64_t timestamp = 0;

    // 可选 GPS 信息
    uint64_t gps_timestamp = 0;
    std::string datetime;
    
    // 可选 PPS 信息
    uint64_t pps_timestamp = 0;
};

class SubtitleSyncManager {
public:
    static SubtitleSyncManager& instance();

    void insert(int64_t pts, double timestamp);
    std::optional<double> query(int64_t pts);
    void clear();
    void setMaxEntries(size_t max_entries);

private:
    SubtitleSyncManager() = default;

    std::mutex mtx_;
    std::map<int64_t, double> timestamp_map_;
    std::deque<int64_t> pts_queue_;
    size_t max_entries_ = 30;  // 默认保留最近 30 条
};

}  // namespace WD
